import router from '@/router'
import { getToken } from './utils/auth'

const whiteList = ['/login', '/404'] // 配置白名单

// permisson.js 的 beforeEach 中
router.beforeEach((to, from, next) => {
  const token = getToken()
  if (whiteList.includes(to.path)) {
    next() // 白名单直接放行
  } else if (token) {
    next() // 有 token 允许访问
  } else {
    next({
      path: '/login',
      query: { redirect: to.fullPath }
    })
  }
})
